package com.banshuibao.bsb_android.util;

import android.os.CountDownTimer;

/**
 * Created by wangpan on 2017/12/29.
 */

public class DownTimerUtil {
    CountDownTimer countDownTimer;
    OnTimerChangeListener onTimerChangeListener;
    public void startTime(long countTime,long interval){
        if(countDownTimer == null){
            countDownTimer = new CountDownTimer(countTime,interval) {
                @Override
                public void onTick(long l) {
                    if(onTimerChangeListener!=null){
                        onTimerChangeListener.OnTick(l);
                    }
                }

                @Override
                public void onFinish() {
                    if(onTimerChangeListener!=null){
                        onTimerChangeListener.OnFinish();
                    }
                }
            };
        }
        countDownTimer.start();
    }

    public void endTimer(){
        if(countDownTimer!=null){
            countDownTimer.cancel();
            countDownTimer = null;
        }
    }

   public interface OnTimerChangeListener{
        void OnTick(long l);
        void OnFinish();
    }

    public void setOnTimerChangeListener(OnTimerChangeListener listener){
        this.onTimerChangeListener = listener;
    }
}
